<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/05/26 22:02:02 $)
// $RCSfile: client_myaccount.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./includes/functions_users.php");
require_once ("./includes/functions_customfields.php");
$template->loadLanguageSection("myaccount");

if (empty($_SWIFT["user"]["userid"]))
{
	exit;
}

$template->assign("navigation", '<a href="index.php" id="navlink">'.$_SWIFT["language"]["navhome"].'</a> &raquo; <a href="index.php?_m=core&_a=myaccount" id="navlink">'.$_SWIFT["language"]["myaccount"]."</a>");

if ($_POST["step"] == "1")
{
	if (trim($_POST["fullname"]) == "" || !checkCustomFieldContent(CUSTOMFIELD_USER))
	{
		$template->assign("errormessage", $_SWIFT["language"]["requiredfieldempty"]);
		unset($_POST["step"]);
	} else {
		updateUserClientCP($_SWIFT["user"]["userid"], $_POST["fullname"]);

		updateCustomFields(CUSTOMFIELD_USER, $_SWIFT["user"]["userid"], false, $_SWIFT["user"]["userid"]);
		header("location: index.php?_m=core&_a=myaccount&confirm=1");
	}
}

if ($_GET["confirm"] == "1")
{
	$template->assign("infomessage", $_SWIFT["language"]["maupdateconfirm"]);
}

if (empty($_POST["step"]))
{
	$cfrender = renderClientCustomFields(CUSTOMFIELD_USER, $_SWIFT["user"]["userid"], 0, $_SWIFT["user"]["userid"]);
	$template->assign("sectiontitle", $_SWIFT["language"]["myaccount"]);
	$template->assign("sectiondesc", $_SWIFT["language"]["madesc"]);
	$template->assign("cfrender", $cfrender);
	$template->assign("backurl", "index.php");
	$template->assign("fullname", $_SWIFT["user"]["fullname"]);
	$template->assign("primaryemail", $_SWIFT["user"]["primaryemail"]);

	echo $template->displayTemplate("myaccount");
}
?>